$(function(){
	//alert("aa");
	var compiler=$("#username-show").text();
	//alert(compiler);
	
	$.post('jsp/worker/getCompilerTask.jsp', 'compiler='+compiler, function(data) {
		json = eval('('+data+')');
		var result = json.result;
		if(result=="fail"){
			var htmlAppend='';
			htmlAppend='<div>您暂时无任务，请联系管理员分配任务！</div>';
			$("#compilertaskdetail").html(htmlAppend);
		}else{
			var htmlAppend='';
			var subject=json.subject;
			var from=json.from;
			var end=json.end;
			var count=json.count;
			htmlAppend='<div class="input-group"><span class="input-group-addon"><b>学科</b></span><input type="text" class="form-control" id="subject" / readonly="readonly" value="'+subject+'"><span class="input-group-addon"><b>编号</b></span><input type="text" class="form-control" id="id_begin" / readonly="readonly" value="'+from+'"><span class="input-group-addon"><b>至</b></span><input type="text" class="form-control" id="id_end" / readonly="readonly" value="'+end+'"></div><div>&nbsp;&nbsp;&nbsp;共'+count+'个任务</div>';
			$("#compilertaskdetail").html(htmlAppend);
		}
	}); 
　　$("#refrush1").click();
    $("#refrush2").click();
}); 


$("#refrush1").click(function(){
	var compiler=$("#username-show").text();
	//alert(compiler);
	$.post('jsp/worker/workertaskCondition.jsp', 'compiler='+compiler, function(data) {
		json = eval('('+data+')');
		var unfinished=Number(json.unfinished);
		var finished=Number(json.finished);
		var doubt=Number(json.doubt);
		var pass=Number(json.pass);
		var unpass=Number(json.unpass);
		var uncheck=Number(json.uncheck);
		var total=unfinished+finished+doubt;
		var finishtotal=pass+unpass+uncheck;
		//alert(unfinished+" "+finished+" "+doubt+" "+total);
		//alert(pass+" "+unpass+" "+uncheck);
		$("#process1").css({"width":+(finished/total*100).toFixed(2)+"%"});
		document.getElementById("process1").innerHTML=(finished/total*100).toFixed(2)+"%";
		$("#process2").css({"width":+Math.round(doubt/total*1000)/1000*100+"%"});
		document.getElementById("process2").innerHTML=(doubt/total*100).toFixed(2)+"%";
		$("#process3").css({"width":+Math.round(unfinished/total*1000)/1000*100+"%"});
		document.getElementById("process3").innerHTML=(unfinished/total*100).toFixed(2)+"%";
		
		$("#process4").css({"width":+Math.round(finished/total*1000)/1000*100+"%"});
		document.getElementById("process4").innerHTML=finished+"条";
		$("#process5").css({"width":+Math.round(doubt/total*1000)/1000*100+"%"});
		document.getElementById("process5").innerHTML=doubt+"条";
		$("#process6").css({"width":+Math.round(unfinished/total*1000)/1000*100+"%"});
		document.getElementById("process6").innerHTML=unfinished+"条";
		
		$("#process7").css({"width":+Math.round(pass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process7").innerHTML=(pass/finishtotal*100).toFixed(2)+"%";
		$("#process8").css({"width":+Math.round(unpass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process8").innerHTML=(unpass/finishtotal*100).toFixed(2)+"%";
		$("#process9").css({"width":+Math.round(uncheck/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process9").innerHTML=(uncheck/finishtotal*100).toFixed(2)+"%";
		
		$("#process10").css({"width":+Math.round(pass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process10").innerHTML=pass+"条";
		$("#process11").css({"width":+Math.round(unpass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process11").innerHTML=unpass+"条";
		$("#process12").css({"width":+Math.round(uncheck/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process12").innerHTML=uncheck+"条";
		
	});
	
});

$("#refrush2").click(function(){
	var subject="所有";
	var compiler=$("#username-show").text();
	//alert(subject+";"+compiler);
	if(compiler==null || compiler==""){
		alert("请输入编撰者姓名！");
	}else{
		$.post('jsp/worddictionary/getWordlist.jsp', 'subject='+subject+'&compiler='+compiler, function(data) {
			json = eval('('+data+')');
			var finishedlist=json.finishedlist;//当记录为空的时候返回的是：[],长度为2
			var doubtlist=json.doubtlist;
			var unfinishedlist=json.unfinishedlist;
			var unpass=json.unpass;
			var unchecked=json.unchecked;
			var idcount=0;
			//alert(unfinishedlist);
			$("#finished").html('');
			$("#doubt").html('');
			$("#unfinished").html('');
			$("#unpass").html('');
			$("#uncheck").html('');
			
			if(finishedlist.length>2){
				finishedlist=finishedlist.substring(1,finishedlist.length-1);
				var finili =finishedlist.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(finili.length<displaycount){displaycount=finili.length}
				var displaycount=finili.length;
				//alert(displaycount);
				for(var i=0;i<displaycount;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+finili[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#finished").html(htmlAppend);
				//alert("aa");
			}
			
			//alert(doubtlist.length);
			if(doubtlist.length>2){
				
				doubtlist=doubtlist.substring(1,doubtlist.length-1);
				var douli =doubtlist.split(",");
				var htmlAppend2='';
				//var displaycount2=20;//展示20个即可
				//if(douli.length<20){displaycount2=douli.length}
				var displaycount2=douli.length;
				for(var i=0;i<displaycount2;i++){
					htmlAppend2=htmlAppend2+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+douli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#doubt").html(htmlAppend2);
			}
			
			//alert(unfinishedlist.length);
			
			if(unfinishedlist.length>2){
				unfinishedlist=unfinishedlist.substring(1,unfinishedlist.length-1);
				var unfinili =unfinishedlist.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unfinili.length<displaycount){displaycount=unfinili.length}
				var displaycount3=unfinili.length;
				//alert(displaycount3);
				for(var i=0;i<displaycount3;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unfinili[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#unfinished").html(htmlAppend);
			}
			if(unpass.length>2){
				unpass=unpass.substring(1,unpass.length-1);
				var unpassli =unpass.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unpassli.length<20){displaycount=unpassli.length}
				var displaycount4=unpassli.length;
				for(var i=0;i<displaycount4;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unpassli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#unpass").html(htmlAppend);
			}
			if(unchecked.length>2){
				//alert(unchecked);
				unchecked=unchecked.substring(1,unchecked.length-1);
				var unchecli =unchecked.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unchecli.length<20){displaycount=unchecli.length}
				var displaycount5=unchecli.length;
				for(var i=0;i<displaycount5;i++){
					//alert(unchecli[i]);
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unchecli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#uncheck").html(htmlAppend);
			}
		});
	}
	
});

function getDetail(elem){
	var chinese=$(elem).html().trim();//记得去掉空格~
	chinese=chinese.replace(/&nbsp;/g,"");//记住这个写法：/要被替换的内容/g
	//alert(chinese);
    //以防词重复，把编撰者的姓名也传过去.
	var compiler=$("#username-show").text();
	
	$.post('jsp/worddictionary/getWord.jsp', 'chinese='+chinese+'&compiler='+compiler, function(data) {
        //alert("bb");
		json = eval('('+data+')');//第一次解析
		var res=json.wordjson;
		
		json = eval('('+res+')');//第二次解析
		//var number=json.number;
		//alert(json.synonym1);
		$("#chosenWords").text(json.chinese);
		$("#term-subject").val(json.subject);
		$("#id_term").val(json.number);
		$("#term-chi").val(json.chinese);
		$("#word-class").val(json.cixing);
		$("#recommendName").val(json.formalword);
		$("#recommendTrans").val(json.formaltranslation);
		$("#term-eng1").val(json.english1);
		$("#term-frequen1").val(json.frequence1);
		$("#chi_context1").val(json.chincondition1);
		$("#eng_context1").val(json.engcondition1);
		$("#term-eng2").val(json.english2);
		$("#term-frequen2").val(json.frequence2);
		$("#chi_context2").val(json.chincondition2);
		$("#eng_context2").val(json.engcondition2);
		$("#term-eng3").val(json.english3);
		$("#term-frequen3").val(json.frequence3);
		$("#chi_context3").val(json.chincondition3);
		$("#eng_context3").val(json.engcondition3);
		$("#term-eng4").val(json.english4);
		$("#term-frequen4").val(json.frequence4);
		$("#chi_context4").val(json.chincondition4);
		$("#eng_context4").val(json.engcondition4);
		$("#term-eng5").val(json.english5);
		$("#term-frequen5").val(json.frequence5);
		$("#chi_context5").val(json.chincondition5);
		$("#eng_context5").val(json.engcondition5);
		$("#cizu1").val(json.cizu1);
		$("#translation1").val(json.translation1);
		$("#cizu2").val(json.cizu2);
		$("#translation2").val(json.translation2);
		$("#cizu3").val(json.cizu3);
		$("#translation3").val(json.translation3);
		$("#cizu4").val(json.cizu4);
		$("#translation4").val(json.translation4);
		$("#cizu5").val(json.cizu5);
		$("#translation5").val(json.translation5);
		$("#synonym1").val(json.synonym1);
		$("#synonym2").val(json.synonym2);
		$("#synonym3").val(json.synonym3);
		$("#synonym4").val(json.synonym4);
		$("#synonym5").val(json.synonym5);
		$("#antonym1").val(json.antonym1);
		$("#antonym2").val(json.antonym2);
		$("#antonym3").val(json.antonym3);
		$("#antonym4").val(json.antonym4);
		$("#antonym5").val(json.antonym5);
		$("#related").val(json.linkword);
		$("#personInCharge").val(json.compiler);
		$("#insertdate").val(json.date);
		$("#term_situation").val(json.status);
		$("#is_pass").val(json.ispass);
		$("#updateRemark").val(json.advice);
		$("#updatedate").val(json.renewdate);
	});
};

$("#save_edit").click(function(){
	//alert("kk");
	var word=new Object(); 
	
	word.number=$("#id_term").val();
	word.chinese=$("#chosenWords").text();
	word.subject=$("#term-subject").val();
	word.cixing=$("#word-class").val();
	word.english1=$("#term-eng1").val();
	word.frequence1=$("#term-frequen1").val();
	word.chinese=$("#term-chi").val();
	word.formalword=$("#recommendName").val();
	word.formaltranslation=$("#recommendTrans").val();
	word.chincondition1=$("#chi_context1").val();
	word.engcondition1=$("#eng_context1").val();
	word.english2=$("#term-eng2").val();
	word.frequence2=$("#term-frequen2").val();
	word.chincondition2=$("#chi_context2").val();
	word.engcondition2=$("#eng_context2").val();
	word.english3=$("#term-eng3").val();
	word.frequence3=$("#term-frequen3").val();
	word.chincondition3=$("#chi_context3").val();
	word.engcondition3=$("#eng_context3").val();
	word.english4=$("#term-eng4").val();
	word.frequence4=$("#term-frequen4").val();
	word.chincondition4=$("#chi_context4").val();
	word.engcondition4=$("#eng_context4").val();
	word.english5=$("#term-eng5").val();
	word.frequence5=$("#term-frequen5").val();
	word.chincondition5=$("#chi_context5").val();
	word.engcondition5=$("#eng_context5").val();
	word.cizu1=$("#cizu1").val();
	word.translation1=$("#translation1").val();
	word.cizu2=$("#cizu2").val();
	word.translation2=$("#translation2").val();
	word.cizu3=$("#cizu3").val();
	word.translation3=$("#translation3").val();
	word.cizu4=$("#cizu4").val();
	word.translation4=$("#translation4").val();
	word.cizu5=$("#cizu5").val();
	word.translation5=$("#translation5").val();
	word.synonym1=$("#synonym1").val();
	word.synonym2=$("#synonym2").val();
	word.synonym3=$("#synonym3").val();
	word.synonym4=$("#synonym4").val();
	word.synonym5=$("#synonym5").val();
	word.antonym1=$("#antonym1").val();
	word.antonym2=$("#antonym2").val();
	word.antonym3=$("#antonym3").val();
	word.antonym4=$("#antonym4").val();
	word.antonym5=$("#antonym5").val();
	word.linkword=$("#related").val();
	word.compiler=$("#personInCharge").val();
	word.date=$("#insertdate").val();
	word.status=$("#term_situation").val();
	word.ispass=$("#is_pass").val();
	word.advice=$("#updateRemark").val();
	word.renewdate=$("#updatedate").val();
	
	//alert(word.status+";"+word.ispass);
	if(word.status=="已完成" && (word.ispass==""||word.ispass==null||word.ispass=="null")){
		//alert("cao");
		word.ispass="未审查";
	}
	if(word.status=="已完成" && word.ispass=="未通过"){
		alert("【仅在测试阶段提示：】若对于未通过的词条进行保存，系统自动将状态修改为:未审查，再交由管理员审查！Please see see是否合理哈~");
		word.ispass="未审查";
	}
	if(word.ispass=="通过" && word.status!="已完成"){
		alert("你惨了！完成状态应该为【已完成】,请修改后重新");
	}
	
	var wordobj = JSON.stringify(word); 
	
	$.post('jsp/worker/updateWord.jsp', 'wordobj='+wordobj, function(data) {
        //alert("bb");
		json = eval('('+data+')');//第一次解析
		var res=json.result;
		//alert(res);
		if(res=="success"){
			alert("保存成功!");
			$("#refrush2").click();
		}else{
			alert("保存失败!请重新保存！若多次无法保存，请联系管理员！");
		}
		
		
	});
});


